import { http } from "@/utils/http";

type SendVerifyCode = {
  mobile: string
}
export const sendVerifyCodeURL = '/usercenter/login.sendCode'
/**
 * 发送验证码接口
 * @param params 
 * @returns 
 */
export async function sendVerifyCode(params: SendVerifyCode) {
  return http.get(sendVerifyCodeURL, { params })
}


/**
 * 游戏类型
 */
export type GameType = Record<string, string>

/**
 * 直播平台
 */
export type LivePlatform = Record<string, string>

/**
 * 直播时长
 */
export type LiveTime = Record<string, string>

export type Scale = LiveTime
export type ManPost = LiveTime
/**
 * 返回数据
 */
interface ApplayAnchorSelect {
  /**
   * 游戏类型
   */
  game_type: GameType;
  /**
   * 直播平台
   */
  live_platform: LivePlatform;
  /**
   * 直播时长
   */
  live_time: LiveTime;
  scale: Scale
  man_post: ManPost
  [property: string]: any;
}


export type FormatedApplayAnchorSelect = Record<keyof ApplayAnchorSelect, [number, string][]>
const ApplayAnchorSelectCache: FormatedApplayAnchorSelect = {

}
/**
 * 获取申请主播下拉选项配置
 * @returns 
 */
export const getApplayAnchorSelect = async () => {
  if (Object.keys(ApplayAnchorSelectCache).length) {
    return ApplayAnchorSelectCache
  }
  return http.get<ApplayAnchorSelect>('/cooperate/select.options').then(({ data }) => {
    Object.entries(data).forEach(item => {
      const [key, value] = item
      ApplayAnchorSelectCache[key as keyof ApplayAnchorSelect] = Object.entries(value).map(([k, v]) => [Number.parseInt(k as string), v as string])
    })
    return ApplayAnchorSelectCache
  })
}